package com.yx.shop.tools;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> {

    private Integer code;

    private String msg;

    private T data;

    public static <T> R<T> ok(T data) {
        return new R<T>(200, "操作成功", data);
    }

    public static <T> R<T> ok(String msg, T data) {
        return new R<T>(200, msg, data);
    }

    public static <T> R<T> success() {
        return new R<>(200, "success", null);
    }

    public static <T> R<T> success(T t1) {
        return new R<>(200, "success", t1);
    }

    //    public static <T> R<T> build(Integer code, String msg, T t1) {
//        return new R<>(code, msg, t1);
//    }
    public static <T> R<T> build(S s, T data) {
        return new R<T>(s.getCode(), s.getMsg(), data);
    }

    public static <T> R<T> failure() {
        return new R<>(500, "failure", null);
    }

    public static <T> R<T> failure(String s) {
        return new R<>(500, s, null);
    }
}